(
	function (factory) {
		if (typeof define === 'function' && define.amd) {
			define(['jquery',"underscore","Waves","ExtFullScreen","SlimScroll"], function($,_,wavesjs) {
				factory($,_,wavesjs);
			});
		} else if (typeof module === 'object' && module.exports) {
			var wavesjs = require('Waves');
			var _ = require('underscore');
			module.exports = function( root, jQuery ) {
				if ( jQuery === undefined ) {
					if ( typeof window !== 'undefined' ) {
						jQuery = require('jquery');
					}
					else {
						jQuery = require('jquery')(root);
					}
				}
				factory(jQuery,_,wavesjs);
			};
		} else {
			factory(jQuery,_,Waves);
		}
	}(
	function ($,_,Waves){
		"use strict";
		var extAssist = function() {
			this.elementBody=$("body");
		};
		extAssist.prototype= {
			initWaves: function () {
				if (typeof Waves != "undefined") Waves.init();
			},
			initTilte:function(title){
				$("title").text(title);
			},
			initUpScroll: function () {
				var self=this;
				var upScroll = $("#btn-scroll-up");
				$(window).scroll(function () {
					if ($(window).scrollTop() > 100) {
						upScroll.addClass("display")
					} else {
						if (upScroll.hasClass("display")) {
							upScroll.removeClass("display")
						}
					}
				});
				upScroll.off("click").on("click", function () {
					self.bodyScrollTop(0,300);
				});
			},
			bodyScrollTop:function(top,time){
				top=top||0;
				time=time||0;
				$('html,body').animate({scrollTop: top+'px'}, time);
			},
			initNavMenu:function(menuId){
				var self=this;
				var li=$("#menu_"+menuId).parent();
				if(li.length>0){
					setTimeout(function () {
						if(!li.hasClass("active")){self._cancelNavMenu()}
						li.addClass("active");
						var ulParent,liParent;
						var ul=li.parent();
						if(ul.hasClass("submenu")){
							liParent=ul.parent("li.has-submenu");
							ulParent=liParent.parent();
							liParent.addClass("active");
						}
						if(ul.hasClass("navigation-menu")){
							ulParent=ul;
							liParent=li;
						}
						//if(ul.hasClass("navigation-menu")){
							var lenUl=ulParent.width();
							var lenLi=liParent.width();
							var ind=liParent.index();
							var l=0,r=0;
							if(ind==0){
								l=0;
								r=lenUl-lenLi;
							}else if(ind==ulParent.length-1){
								l=lenUl-lenLi;
								r=0;
							}else{
								$.each(liParent.prevAll("li"),function (i,item) {return l+=$(item).width();});
								$.each(liParent.nextAll("li"),function (i,item) {return r+=$(item).width();});
							}
						//}
						$("#navigation").find(".indicator").animate({left:l,right:r});
					},50)
				}else{
					$("#navigation").find(".indicator").css({left:"auto",right:"auto"});
					self._cancelNavMenu();
				}
			},
			_cancelNavMenu:function () {
				$("#navigation").find(".navigation-menu li").removeClass("active");
			},
			init: function () {
				var self = this;
				$(function () {
					self.initWaves();
					self.bodyScrollTop(0);
					self._convertInitResult();
					self._setAjaxMessageCode();
				});
			},
			initLayoutIndex:function(){
				this.elementWrapper=$("#wrapper");
				this.initUpScroll();
				$("#btn_fullscreen").ExtFullScreen();
				this.bodyScrollTop(0);
			},
			initParamExt:function(json){
				json=json||{};
				//// todo Ext 参数扩展 预留新需求
				var param= $.ExtCommon.initMergeJson({}, json);
				return param;
			},
			goUrlHref:function(url){
				//// todo Ext 扩展Url参数 预留新需求
				$.ExtCommon.goLocationHref(url);
			},
			//设置错误编码对应提示信息
			_setAjaxMessageCode:function(){
				var json={
					"200":"成功!",
					"100":"test"
				};
				$.ExtAjax.setAjaxMessageCode(json);
			},
			//转换结果结构
			_convertInitResult:function(){
				$.ExtAjax.convertResultCallback=function(res){
					var temp={ret:res.ret,success:false,msg:"",data:null};
					temp.code=res.ret.toString();
					if(temp.code=="200"){
						temp.success = true;
						temp.data = res.data;
					}else{
						if(temp.code=="20001"){
							window.location.href = "#login";
							return false;
						}else {
							temp.success = false;
							temp.msg=$.ExtAjax.getCodeMsg(temp.code,res.err_msg);
						}
					}
					temp.err_msg=temp.msg;
					return temp
				}
			}
		};
		$.ExtAssist = new extAssist;
		$.ExtAssist.Constructor = extAssist;
		$.ExtAssist.init();
	})
);


